<!DOCTYPE html>
<html>
<head>
    <title>设备维修工单</title>
    #parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak>
    <div>
        <Row :gutter="16" style="margin: 8px 0px 0px 1px">
            <div class="search-group">
                <i-col span="4">
                    <i-input v-model="q.name" @on-enter="query" placeholder="设备名称"></i-input>
                </i-col>
                <i-col span="4">
                    <i-input v-model="q.repairCode" @on-enter="query" placeholder="工单编号"></i-input>
                </i-col>
                <i-col span="4">
                    <Date-picker :disabled="isDisabled" type="date" v-model="q.beginTime" placeholder="请输入报修/维修开始时间"></Date-picker>
                </i-col>
                <i-col span="4">
                    <Date-picker :disabled="isDisabled" type="date" v-model="q.endTime" placeholder="请输入报修/维修截止时间"></Date-picker>
                </i-col>
                <i-button @click="query">查询</i-button>
                <i-button @click="reloadSearch">重置</i-button>
            </div>
        </Row>
        <table id="jqGrid"></table>
    </div>
</div>

<script>
    $(function () {
        $("#jqGrid").Grid({
            url: '../devRepairRecord/list',
            colModel: [
                {label: '工单编号', name: 'repairCode', index: 'REPAIR_CODE'},
                {label: '设备名称', name: 'devName', index: 'DEV_NAME'},
                {label: '设备编码', name: 'devCode', index: 'DEV_CODE'},
                {
                    label: '状态', name: 'devStatus', index: 'DEV_STATUS',
                    formatter: function (value) {
                        return sysEnums.REPAIR_TICKET_STATUS[value];
                    }
                },
                {label: '报修时间', name: 'uploadDate', index: 'UPLOAD_DATE'},
                {label: '维修人员', name: 'repairUsername', index: 'REPAIR_USER_NAME'},
                {label: '开始维修时间', name: 'repairStartDate', index: 'REPAIR_START_DATE'},
                {label: '结束维修时间', name: 'repairEndDate', index: 'REPAIR_END_DATE'},
                {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
                {label: 'devId', name: 'devId', index: 'DEV_ID', hidden: true},
                {label: 'workshopId', name: 'workshopId', index: 'WORKSHOP_ID', hidden: true},
                {label: 'repairUser', name: 'repairUser', index: 'REPAIR_USER', hidden: true}
            ]
        });
    });

    let vm = new Vue({
        el: '#rrapp',
        data: {
            q: {
                name: '',
                repairCode:'',
                beginTime: '',
                endTime: '',
            },
            isDisabled: false
        },
        methods: {
            query: function () {
                vm.reload();
            },
            reload: function (event) {
                vm.showList = true;
                var page = $("#jqGrid").jqGrid('getGridParam', 'page');

                var beginTime = vm.q.beginTime;
                if (beginTime != "" && beginTime != "null") {
                    var date = new Date(beginTime);
                    // beginTime = date.format("yyyy-MM-dd");
                    beginTime = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
                }
                var endTime = vm.q.endTime;
                if (endTime != "" && endTime != "null") {
                    var date = new Date(endTime);
                    endTime = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
                }

                $("#jqGrid").jqGrid('setGridParam', {
                    postData: {
                        'repairCode':vm.q.repairCode,
                        'devName': vm.q.name,
                        'beginTime': beginTime,
                        'endTime': endTime
                    },
                    page: page
                }).trigger("reloadGrid");
                vm.handleReset('setGridParam');
            },
            reloadSearch: function () {
                vm.q = {
                    name: '',
                    repairCode:'',
                    beginTime: '',
                    endTime: ''
                };
                vm.reload();
            },
            handleSubmit: function (name) {
                handleSubmitValidate(this, name, function () {
                    vm.saveOrUpdate()
                });
            },
            handleReset: function (name) {
                handleResetForm(this, name);
            }
        }
    });

    var getSparePart = function () {
        let result = getSelectedRowData("#jqGrid");
        var id = result.id;
        if (id == null) {
            return false;
        } else {
            return result;
        }
    }
</script>
</body>
</html>
